package com.dshore.messagecenter.controller.topicqueue;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.dshore.messagecenter.service.topicQueue.QueueChartService;

/**
 * 主题队列图表
 *
 */

@Controller
@RequestMapping("/queueChart/")
public class QueueChartController {
	
	@Autowired
	private QueueChartService queueChartService;
	
	/**
	 * 1)获取具体队列的实时消息流量表
	 */
	@RequestMapping(value = "getOneMsgFlow", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, List<String>> getOneMsgFlow(String tId, String topicQueueNo) {
//		System.out.println("===============具体队列的实时消息流量表===============");
		return queueChartService.getOneMsgFlow(tId, topicQueueNo);
	}
	
	/**
	 * 2)获取具体队列的实时消息发送延时
	 */
	@RequestMapping(value = "getOneMsgSendDelay", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, List<String>> getOneMsgSendDelay(String tId, String topicQueueNo) {
//		System.out.println("===============具体队列的实时消息发送延时===============");
		return queueChartService.getOneMsgSendDelay(tId, topicQueueNo);
	}


	/**
	 * 3)获取具体队列的内存实时占用情况
	 */
	@RequestMapping(value = "getOneMemoryStatus", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, List<String>> getOneMemoryStatus(String tId, String topicQueueNo) {
//		System.out.println("===============具体队列的内存实时占用情况===============");
//		System.out.println("tId: " + tId + ", topicQueueNo: " + topicQueueNo);
		return queueChartService.getOneMemoryStatus(tId, topicQueueNo);
	}
	
	/**
	 * 4)获取具体队列的磁盘I/O
	 */
	@RequestMapping(value = "getOneDiskIO", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, List<String>> getOneDiskIO(String tId, String topicQueueNo) {
//		System.out.println("===============获取具体队列的磁盘I/O===============");
//		System.out.println("tId: " + tId + ", topicQueueNo: " + topicQueueNo);
		return queueChartService.getOneDiskIO(tId, topicQueueNo);
	}
	
	/**
	 * 5)拓扑图获取应用信息
	 * @param tId 队列主键
	 * @return
	 */
	@RequestMapping(value = "getAppInfo", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> getAppInfo(String tId, String topicQueueNo) {

		Map<String, Object> map = queueChartService.getAppInfo(tId,topicQueueNo);
//		System.out.println("应用拓扑图信息: " + map);
		return map;
		
	}
	
	
	/**
	 * 实时监控页面
	 * @param tId 队列主键
	 * @return
	 */
	@RequestMapping("page")
	public ModelAndView page(String tId,String topicQueueNo) {
		ModelAndView mv = new ModelAndView();
		String topicQueueName = queueChartService.getTopicQueueName(tId);
		mv.setViewName("topicqueue/queueChart");
		mv.addObject("topicQueueName", topicQueueName);
		mv.addObject("tId", tId);
		mv.addObject("topicQueueNo", topicQueueNo);
		return mv;
	}
	
	
	
	
	
}
